package com.ruoyi.smart.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.smart.service.ICouchdbSmartProcessData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.smart.domain.SmartProcessData;
import com.ruoyi.smart.service.ISmartProcessDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工序数据Controller
 * 
 * @author minwei
 * @date 2022-05-17
 */
//@Api("工序数据")
@RestController
@RequestMapping("/smart/processdata")
public class SmartProcessDataController extends BaseController
{
    @Autowired
    private ISmartProcessDataService smartProcessDataService;
    @Autowired
    private ICouchdbSmartProcessData couchdbSmartProcessData;

    /**
     * 查询工序数据列表
     */
    //@ApiOperation("查询工序数据列表")
    @PreAuthorize("@ss.hasPermi('smart:processdata:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmartProcessData smartProcessData)
    {
        startPage();
        List<SmartProcessData> list = smartProcessDataService.selectSmartProcessDataList(smartProcessData);
        couchdbSmartProcessData.saveSmartProcessData(list.get(1));
        return getDataTable(list);
    }

    /**
     * 插入上传数据
     */
    @ApiOperation("插入上传数据")
    @GetMapping("/insertString/{data}")
    public AjaxResult insertString(@PathVariable("data") String data)
    {
        smartProcessDataService.insertString(data);
        return AjaxResult.success();
    }

    /**
     * 导出工序数据列表
     */
    @PreAuthorize("@ss.hasPermi('smart:processdata:export')")
    @Log(title = "工序数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmartProcessData smartProcessData)
    {
        List<SmartProcessData> list = smartProcessDataService.selectSmartProcessDataList(smartProcessData);
        ExcelUtil<SmartProcessData> util = new ExcelUtil<SmartProcessData>(SmartProcessData.class);
        util.exportExcel(response, list, "工序数据数据");
    }

    /**
     * 获取工序数据详细信息
     */
    //@ApiOperation("获取工序数据详细信息")
    @PreAuthorize("@ss.hasPermi('smart:processdata:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(smartProcessDataService.selectSmartProcessDataById(id));
    }

    /**
     * 新增工序数据
     */
    //@ApiOperation("新增工序数据")
    @PreAuthorize("@ss.hasPermi('smart:processdata:add')")
    @Log(title = "工序数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmartProcessData smartProcessData)
    {
        return toAjax(smartProcessDataService.insertSmartProcessData(smartProcessData));
    }

    /**
     * 修改工序数据
     */
    //@ApiOperation("修改工序数据")
    @PreAuthorize("@ss.hasPermi('smart:processdata:edit')")
    @Log(title = "工序数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmartProcessData smartProcessData)
    {
        return toAjax(smartProcessDataService.updateSmartProcessData(smartProcessData));
    }

    /**
     * 删除工序数据
     */
    //@ApiOperation("删除工序数据")
    @PreAuthorize("@ss.hasPermi('smart:processdata:remove')")
    @Log(title = "工序数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(smartProcessDataService.deleteSmartProcessDataByIds(ids));
    }
}
